home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / COMPARAT.H < prev    next >
C/C++ Source or Header  |  1992-08-23  |  906b  |  28 lines

  1. // This is in the public domain without warranties expressed or implied.
  2. //
  3. // Created: JAM 08/21/92 -- Initial design and implementation (ref. Stroustrup)
  4. //
  5. // The Comparator class template allows other class templates (eg, Range)
  6. // to compare values of the type they are instantiated with without
  7. // requiring that the values have the "<" and ">" operators defined.
  8. //
  9.  
  10. #ifndef COMPARATORH
  11. #define COMPARATORH
  12.  
  13. #include <string.h>        // for strcmp()
  14.  
  15. template<class T> struct CoolComparator {
  16.    inline static int lessthan(const T& a, const T& b) { return a<b; }
  17.    inline static int equal(const T& a, const T& b)    { return a==b; }
  18. };
  19.  
  20. // define char* Comparator since so common
  21. struct CoolComparator<char*> {
  22.    static int lessthan(char* a, char* b) { return strcmp(a,b)<0; }
  23.    static int equal(char* a, char* b) { return strcmp(a,b)==0; }
  24. };
  25.  
  26. #endif // COMPARATORH
  27.  
  28.